using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace LeisureCenter.Controls
{
    public class ProgressBar : Control
    {
        private int min;

        public int Min
        {
            get { return min; }
            set 
            {
                min = value;
                Invalidate();
            }
        }

        private int max = 100;

        public int Max
        {
            get { return max; }
            set 
            {
                max = value;
                Invalidate();
            }
        }

        private int position;

        public int Position
        {
            get { return position; }
            set
            {
                position = value;
                Invalidate();
            }
        }

        public ProgressBar()
        {
            InitializeComponent();

            SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
        }

        private void InitializeComponent()
        {
            this.SuspendLayout();
            // 
            // ProgressBar
            // 
            this.Paint += new System.Windows.Forms.PaintEventHandler(this.ProgressBar_Paint);
            this.ResumeLayout(false);
        }

        private void ProgressBar_Paint(object sender, PaintEventArgs e)
        {
            if (max > min)
            {
                Brush brush = new SolidBrush(ForeColor);
                Panel.FillRoundRect(e.Graphics, new Rectangle(0, 0, Width * (position - min) / (max - min), Height), brush);
                brush.Dispose();
            }
        }        
    }
}
